<?php

namespace app\v1\model;

use think\db\Query;
use think\Model;
use think\model\concern\SoftDelete;

class Question extends Model
{
    use SoftDelete;
    protected $deleteTime = 'delete_time';

    /**
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getAllOrderByAsc(int $id = 0)
    {
        $res = $this->with('questionOption')
        ->field('id,title')
        ->order('order', 'asc');
        if ($id > 0) {
            $res = $res->find($id);
        } else {
            $res = $res->select();
        }
        return $res;
    }

    /**
     * 问题的选项
     * @return \think\model\relation\HasMany
     */
    public function questionOption()
    {
        return $this->hasMany(Option::class);
    }
}
